package edu.lingnan.house.controller;

import edu.lingnan.house.pojo.TbHouse;
import edu.lingnan.house.pojo.TbUser;
import edu.lingnan.house.service.HostService_lxj;
import edu.lingnan.house.service.HouseService_lxj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class HouseController_lxj {
    @Autowired
    private HouseService_lxj houseService;

    //房主申请上架房子
    @PostMapping("/test1")
    @ResponseBody
    public String testAddHouse(@RequestBody TbHouse house ){
        int i = houseService.addHouse(house);
        return "ok";
    }

    //房主查看房子 根据user_id
    /*@GetMapping("/test2")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse(String userId){
        List<TbHouse> houses = houseService.findHouse(userId);
        return houses;
    }*/
    @GetMapping("/test2")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse(HttpSession session){
        TbUser tbUser = (TbUser) session.getAttribute("tbUser");
        List<TbHouse> houses = houseService.findHouse("200");
        return houses;
    }

    //房主查看房子 根据user_id  state
    @GetMapping("/test3")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse(String userId,Integer state){
        List<TbHouse> houses = houseService.findHouse(userId,state);
        return houses;
    }

    //房主查看 申请上架中 的房子
    /*@GetMapping("/test4")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse1(String userId){
        List<TbHouse> houses = houseService.findHouse1(userId);
        return houses;
    }*/
    @GetMapping("/test4")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse1(HttpSession session){
        TbUser tbUser = (TbUser) session.getAttribute("tbUser");
        List<TbHouse> houses = houseService.findHouse1("200");
        return houses;
    }

    //房主查看 上线中 的房子
    /*@GetMapping("/test5")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse2(String userId){
        List<TbHouse> houses = houseService.findHouse2(userId);
        return houses;
    }*/
    @GetMapping("/test5")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse2(HttpSession session){
        TbUser tbUser = (TbUser) session.getAttribute("tbUser");
        List<TbHouse> houses = houseService.findHouse2("200");
        return houses;
    }

    //房主查看 下线 的房子
    /*@GetMapping("/test6")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse3(String userId){
        List<TbHouse> houses = houseService.findHouse3(userId);
        return houses;
    }*/
    @GetMapping("/test6")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse3(HttpSession session){
        TbUser tbUser = (TbUser) session.getAttribute("tbUser");
        List<TbHouse> houses = houseService.findHouse3("200");
        return houses;
    }

    //房主查看 已出售并使用中 的房子
    /*@GetMapping("/test7")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse4(String userId){
        List<TbHouse> houses = houseService.findHouse4(userId);
        return houses;
    }*/
    @GetMapping("/test7")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse4(HttpSession session){
        TbUser tbUser = (TbUser) session.getAttribute("tbUser");
        List<TbHouse> houses = houseService.findHouse4("200");
        return houses;
    }

    //房主查看 申请下架中 的房子
    /*@GetMapping("/test8")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse5(String userId){
        List<TbHouse> houses = houseService.findHouse5(userId);
        return houses;
    }*/
    @GetMapping("/test8")
    @ResponseBody
    public List<TbHouse> testFindSelfHouse5(HttpSession session){
        TbUser tbUser = (TbUser) session.getAttribute("tbUser");
        List<TbHouse> houses = houseService.findHouse5("200");
        return houses;
    }


    //房主申请下架房子
    @PostMapping("/test9")
    @ResponseBody
    public String testUpdateHouseToAgent(@RequestBody TbHouse house){
        int i = houseService.updateHouseToAgent(house);
        return "ok";
    }

    //中介查询所负责的房子信息
    @GetMapping("/test10")
    @ResponseBody
    public List<TbHouse> testFindHouseByAgentId(String agentId){
        List<TbHouse> houses = houseService.findHouseByAgentId(agentId);
        return houses;
    }

    //中介查询所负责的上架申请信息  agent_id  state取固定值
    @GetMapping("/test11")
    @ResponseBody
    public List<TbHouse> testFindHouseByAgentIdAndSetState(String agentId){
        List<TbHouse> houses = houseService.findHouseByAgentIdAndSetState(agentId);
        return houses;
    }

    //中介查询所负责的下架申请信息  agent_id  state取固定值
    @GetMapping("/test12")
    @ResponseBody
    public List<TbHouse> testFindHouseByAgentIdAndSetState3(String agentId){
        List<TbHouse> houses = houseService.findHouseByAgentIdAndSetState3(agentId);
        return houses;
    }
    //中介审批通过房子上架申请
    @PostMapping("/test13")
    @ResponseBody
    public String testUpdateHouseApply(@RequestBody TbHouse house){
        int i = houseService.updateHouseApplyByAgent(house);
        return "ok";
    }

    //中介审批不通过房子上架申请
    @PostMapping("/test14")
    @ResponseBody
    public String testUpdateDownHouseApply(@RequestBody TbHouse house){
        int i = houseService.updateHouseApplyDownByAgent(house);
        return "ok";
    }

    //中介修改房子信息，如细节描述detail
    @PostMapping("/test15")
    @ResponseBody
    public String testUpdateHouseMessage(@RequestBody TbHouse house){
        int i = houseService.updateHouseMessage(house);
        return "ok";
    }

}
